package com.helloworld.chat.action;


import com.helloworld.chat.cache.CacheManager;
import com.helloworld.chat.cache.UnReadMessageCache;
import com.helloworld.chat.cache.UserCache;
import com.helloworld.chat.entity.User;
import com.helloworld.chat.service.GroupService;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import javax.servlet.http.HttpServletRequest;

/**
 * Created by xdzy on 2017/6/28.
 */
@Controller
@Scope("prototype")
public class HomeAction {
    private static final Logger logger=Logger.getLogger(HomeAction.class);
    @Autowired
    private GroupService groupService;

    public void setGroupService(GroupService groupService) {
        this.groupService = groupService;
    }

    public String home(){
        HttpServletRequest request= ServletActionContext.getRequest();
        int uid= ((User)(request.getSession().getAttribute("loginUser"))).getUid();
        UserCache userCache= CacheManager.getUserCache();
        userCache.changeUserStatus(uid+"","1");
        request.setAttribute("groupList",groupService.getGroupList(uid));
        UnReadMessageCache urmCache=CacheManager.getUnReadMessageCache();
        request.setAttribute("unreads",urmCache.getUnReadMessagesFrom_JSON(uid+""));
        return "home";
    }
}
